<template>
  <el-button type="text" size="medium" icon="el-icon-download" @click="download">下载</el-button>
</template>

<script>
// import { fileDownload } from '@/api/upload'
import { downloadFun } from '@/utils/file'
export default {
  props: {
    file: {
      type: Object,
      default: () => {
        return {
          'id': 'e3558f16-0e3c-4ea5-a8b6-5407a4e45299',
          'suffix': '.doc',
          'old_name': 'doc附件'
        }
      }
    }
  },
  methods: {
  //   blobType() {
  //     let types = ''
  //     switch (this.file.suffix) {
  //       case '.jpg':
  //         types = 'image/jpeg'
  //         break
  //       case '.jpeg':
  //         types = 'image/jpeg'
  //         break
  //       case '.png':
  //         types = 'image/png'
  //         break
  //       case '.gif':
  //         types = 'image/gif'
  //         break
  //       case '.doc':
  //         types = 'application/msword'
  //         break
  //       case '.xls':
  //         types = 'application/vnd.ms-excel'
  //         break
  //       case '.pdf':
  //         types = 'application/pdf'
  //         break
  //       case '.zip':
  //         types = 'application/zip'
  //         break
  //       case '.rar':
  //         types = 'application/x-rar-compressed'
  //         break
  //     }
  //     return types
  //   },
  //   async download() {
  //     const res = await fileDownload({ id: this.file.id || 'e3558f16-0e3c-4ea5-a8b6-5407a4e45299' })
  //     const types = this.blobType()
  //     const blob = new Blob([res], { type: types })
  //     const url = window.URL.createObjectURL(blob)
  //     const link = document.createElement('a')
  //     link.style.display = 'none'
  //     link.href = url
  //     link.setAttribute('download', this.file.old_name || '附件')
  //     document.body.appendChild(link)
  //     link.click()
  //     this.$emit('downloadSuccess')
  //   }

    download() {
      downloadFun(this.file).then(() => {
        this.$emit('downloadSuccess')
      })
    }
  }
}
</script>
